package b1.players
{
	import b1.conifg.*;
	import b1.net.*;
	
	public class PlayerInfo
	{
		//玩家本人的ID号唯一号
		public var id:int;
		//玩家本人的人人网ID
		public var renrenId:int;
		//和玩家本人的关系(-1, 虚拟用户; 0, 本人; 1, 邻居; 2, 好友)
		public var type:int;
		//完成的主线任务
		public var accomplishedTaskId:int;
		//完成的节日任务
		public var accomplishedFestivalTaskId:int;
		//名字
		public var name:String;
		//家的背景类型
		public var homeIndex:int;
		//住在这家的所有动物(ID号)
		public var liveAnimals:Array;
		//拥有的所有动物(ID号)
		public var ownAnimals:Array;
		//包裹
		public var userPackage:PackageInfo;
		//传家宝
		public var heirlooms:Object;
		//上一次取传家宝盒的时间
		public var heirloomBoxFetchTime:int;
		//传家宝盒剩余的骨头		
		public var _heirloomBoxBoneLeft:int;
		//所有的传家宝等级总和
		public var heirloomLevelCount:int;
		//传家宝等级总和的全服排名
//		public var heirloomLevelRank:int;
		//用户的勋章等级
		public var playerHonour:Array;
		//用户的总装备得分
		public var equipScoreCount:int;
		//用户的总装备排名
		public var equipRank:int;
		
		public function PlayerInfo()
		{
			this.id = -1;
			this.renrenId = -1;
			this.type = -1;
			this.accomplishedTaskId = -1;
			this.accomplishedFestivalTaskId = -1;
			this.name = "";
			this.homeIndex = 0;
			this.liveAnimals = new Array();
			this.userPackage = new PackageInfo();
			this.ownAnimals = new Array();	
			this.heirlooms = new Object();
			this.heirloomBoxFetchTime = 0;
			this._heirloomBoxBoneLeft = 0;
			this.heirloomLevelCount = 0;
//			this.heirloomLevelRank = 99999;
			this.playerHonour = new Array(Config.equipColorName.length);
//			this.totalScore = 0;
		}
		
		public function getRankInfo():RankConfig
		{
			var rankConfig:RankConfig;
			for (var i:int = 0; i < Config.rankConfigs.length; i++)
			{
				rankConfig = Config.rankConfigs[i];
				if (equipRank < rankConfig.range)
					break;
			}
			return rankConfig;
		}
		
		public function getNextRankInfo():RankConfig
		{
			var rankConfig:RankConfig;
			for (var i:int = 0; i < Config.rankConfigs.length; i++)
			{
				rankConfig = Config.rankConfigs[i];
				if (equipRank < rankConfig.range)
				{
					if (i > 0)
					{
						return Config.rankConfigs[i - 1];
					}
					else
					{
						return null;
					}
				}
			}
			return null;
		}
		
		public function get heirloomBoxBoneLeft():int
		{
			var boneLeft:int;
			if (_heirloomBoxBoneLeft > 0)
			{
				boneLeft = _heirloomBoxBoneLeft;
			}
			else if (ServerHelper.getInstance().now() >= heirloomBoxFetchTime + Config.heirloomBoxFullTime)
			{
				boneLeft = getRankInfo().heirloomBoxVolume; 
			}
			else
			{
				boneLeft = 0;
			}
			return boneLeft;
		}
		
		//检查是否点亮新的装备勋章
		public function checkNewHonour(newEquipIndex:int, newEquipSet:Object):Boolean
		{
			var newEquipConfig:EquipConfig = Config.objectConfigs[newEquipIndex];
			var equipCount:int = 0;
			//包裹里的装备
			for (var index:String in userPackage.objectList)
			{
				var objectConfig:ObjectConfig = Config.objectConfigs[index];
				if (objectConfig.type == 2 && userPackage.objectList[index] > 0)
				{
					var equipConfig:EquipConfig = objectConfig as EquipConfig;
					if (equipConfig.equipType == newEquipConfig.equipType && equipConfig.color == newEquipConfig.color && equipConfig.index != newEquipConfig.index)
					{
						equipCount++;
					}
				}
			}
			//动物身上的装备
			var myAnimal:AnimalInfo = PlayerInfoHelper.getInstance().animals[ownAnimals[0]];
			for (var position:String in myAnimal.equips)
			{
				var equipInfo:EquipInfo = myAnimal.equips[position];
				equipConfig = Config.objectConfigs[equipInfo.objectIndex] as EquipConfig;
				if (equipConfig.equipType == newEquipConfig.equipType && equipConfig.color == newEquipConfig.color && equipConfig.index != newEquipConfig.index)
				{
					equipCount++;
				}
			}
			//同时得到的新装备
			for (index in newEquipSet)
			{
				equipConfig = Config.objectConfigs[index] as EquipConfig;
				if (equipConfig.equipType == newEquipConfig.equipType && equipConfig.color == newEquipConfig.color && equipConfig.index != newEquipConfig.index)
				{
					equipCount++;
				}
			}
			if (equipCount + 1 >= newEquipConfig.equipNum)
				return true;
			else
				return false;
		}
		
	}
}